#!/usr/bin/env python2.5

import os, sys, anydbm, marshal

from twisted.python import log
from twisted.internet import reactor
from twisted.web import client
from twisted.internet import defer, task

from polarrose.amazon.sss import SimpleStorageService

if __name__ == "__main__":

    from twisted.internet import reactor

    def printResult(response):
        if not response.success:
            print "Error: %s %s" % (response.code, response.message)
        reactor.stop()

    def printError(failure):
        print "failure: " + str(failure)
        reactor.stop()

    # sss-put-object <file> <bucket> <key> [content-type]

    data = open(sys.argv[1], 'rb').read()

    contentType = "binary/octet-stream"
    if len(sys.argv) == 5:
        contentType = sys.argv[4]

    service = SimpleStorageService(key = os.environ.get("AWS_KEY"), secret = os.environ.get("AWS_SECRET"))
    service.putObjectData(sys.argv[2], sys.argv[3], data,contentType).addCallback(printResult).addErrback(printError)
    reactor.run()
    
